﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Molic.Core;
using Molic.Core.Controls.interfaces;
using Spring.Context.Support;
using Spring.Context;

namespace Molic.Main.Managers
{
    public class MolicController : IMolicController
    {
        #region Propriedades
        private IMolicModelFactory _ModelFactory;
        /// <summary>
        /// Model factory registered in the system.
        /// </summary>
        private IMolicModelFactory ModelFactory
        {
            get
            {
                if (_ModelFactory == null)
                {
                    IApplicationContext ctx = ContextRegistry.GetContext();
                    _ModelFactory = (IMolicModelFactory)ctx.GetObject("ModelFactory");
                }
                return _ModelFactory;
            }
        }
        #endregion

        #region Constructors
        public MolicController()
        {}
        #endregion

        #region IMolicController Members

        void IMolicController.ShapeFactory_OnShapeAdded(object sender, Molic.Core.MolicShapeEventArgs e)
        {
            throw new NotImplementedException();
        }

        void IMolicController.OnLoad(object sender, EventArgs e)
        {
            throw new NotImplementedException();
        }

        void IMolicController.canvas_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
        {
            throw new NotImplementedException();
        }

        void IMolicController.canvas_OnMouseDown(System.Windows.Input.MouseButtonEventArgs e)
        {
            throw new NotImplementedException();
        }

        void IMolicController.canvas_OnMouseMove(System.Windows.Input.MouseEventArgs e)
        {
        }

        void IMolicController.canvas_OnLeftUp(object sender, System.Windows.Input.MouseEventArgs args)
        {
        }

        void IMolicController.canvas_OnDrop(System.Windows.DragEventArgs e)
        {
            throw new NotImplementedException();
        }

        #endregion

        #region IMolicController Members

        void IMolicController.canvas_OnLeftDown(object sender, System.Windows.Input.MouseEventArgs args)
        {
        }

        #endregion

        #region IMolicController Members
        /// <summary>
        /// Create a new model.
        /// </summary>
        /// <param name="VisualReference"></param>
        /// <returns></returns>
        public MolicUIElement CreateModel(object VisualReference)
        {
            return ModelFactory.CreateModel(VisualReference);
        }
        /// <summary>
        /// Creates a new model using the models name.
        /// </summary>
        /// <param name="ModelName"></param>
        /// <returns></returns>
        public MolicUIElement CreateModel(string ModelName)
        {
            return ModelFactory.CreateModel(ModelName);
        }

        #endregion

        #region IMolicController Members


        public MolicUIElement CreateModel(string ModelName, Guid id)
        {
            return ModelFactory.CreateModel(ModelName, id);
        }

        #endregion

        #region IMolicController Members
        private System.Windows.Controls.UIElementCollection models;
        /// <summary>
        /// The system models.
        /// </summary>
        public System.Windows.Controls.UIElementCollection Models
        {
            get 
            {
                return models;
            }
            set
            {
                models = value;
            }
        }

        #endregion

        #region IMolicController Members

        public Molic.Core.Services.IMolicSelectionService selectionService;
        /// <summary>
        /// The system selection service.
        /// </summary>
        public Molic.Core.Services.IMolicSelectionService SelectionService
        {
            get
            {
                return selectionService;
            }
            set
            {
                selectionService = value;
            }
        }

        #endregion
    }
}
